import os

from app import create_app
from flask_script import Manager
from flask_migrate import MigrateCommand

# 从环境变量中获取config_name
config_name = os.environ.get('FLASK_CONFIG') or 'default'

# 生成app
app = create_app(config_name)

manager = Manager(app)

# 添加命令行拓展
# 可以在终端输入：
# python manage.py db init  # 创建迁移仓库
# python manage.py db migrate  # 创建迁移脚本
# python manage.py db upgrade  # 提交更改至数据库
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    # python manage.py runserver    # 运行
    manager.run()